package com.nageoffer.shortlink.project.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.shortlink.project.common.convention.result.Result;
import com.nageoffer.shortlink.project.common.convention.result.Results;
import com.nageoffer.shortlink.project.dto.req.ShortLinkCreateReqDTO;
import com.nageoffer.shortlink.project.dto.req.ShortLinkPageReqDTO;
import com.nageoffer.shortlink.project.dto.resp.ShortLinkCreateRespDTO;
import com.nageoffer.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.nageoffer.shortlink.project.service.ShortLinkService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 刘新智
 * @Date: 2025/10/20 19:11
 * @Description: 短链接控制层
 * @Version: v1.0
 */
@RestController
@RequestMapping("api/shortlink/v1/link")
@AllArgsConstructor
public class ShortLinkController {
    private final ShortLinkService shortLinkService;

    /**
     * @description: 创建短链接
     * @author: 刘新智
     * @date: 2025/10/22 10:22
     * @param: [shortLinkCreateReqDTO]
     * @return: com.nageoffer.shortlink.project.common.convention.result.Result<com.nageoffer.shortlink.project.dto.resp.ShortLinkCreateRespDTO>
     **/
    @PostMapping("create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO shortLinkCreateReqDTO) {
        ShortLinkCreateRespDTO shortLinkCreateRespDTO = shortLinkService.createShortLink(shortLinkCreateReqDTO);
        return Results.success(shortLinkCreateRespDTO);
    }


    /**
     * 短链接分页查询
     * @param requestParam 分页查询请求参数
     * @return 短链接分页返回结果
     */
    @PostMapping("/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(@RequestBody ShortLinkPageReqDTO requestParam) {
        IPage<ShortLinkPageRespDTO> result = shortLinkService.pageShortLink(requestParam);
        return Results.success(result);
    }

}
